import 'dart:convert' as converts;

import 'package:collection/collection.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' hide MapType;
import 'package:json_annotation/json_annotation.dart';
import 'package:yt_devops/model/device_config_model.dart';
import 'package:yt_devops/utils/enums.dart';

part 'device_model.g.dart';

@JsonSerializable()
class DeviceModel {
  DeviceModel(
      {this.ammeterType,
      this.capacity,
      this.createBy,
      this.createTime,
      this.activeTime,
      this.onlineTime,
      this.validTime,
      this.sessionStartTime,
      this.offlineTime,
      this.productType,
      this.deviceId,
      this.alarmStatus,
      this.status,
      this.installedCapacity,
      this.manufacturer,
      this.model,
      this.paramsKeyKey,
      this.pileType,
      this.gunNumVal,
      this.tcuNumVal,
      this.remark,
      this.siteCode,
      this.siteId,
      this.siteName,
      this.sn,
      this.uid,
      this.name,
      this.updateBy,
      this.updateTime,
      this.productTypeName,
      this.subsystemId,
      this.subsystemName,
      this.createUserName,
      this.paramConfigType,
      this.productConfigType,
      this.productId,
      this.config,
      this.softVersion,
      this.factoryName,
      this.masterSlaveMode,
      this.masterSlaveSystemName,
      this.forShort,
      this.address,
      this.latitude,
      this.longitude,
      this.map,
      this.ratedPower});

  // 设备名称
  String? name;

  ///1-单项 2-三相
  String? ammeterType;

  ///储能容量
  String? capacity;

  ///创建者
  String? createBy;

  ///创建时间
  String? createTime;

  ///离线时间
  String? offlineTime;

  ///活跃时间
  String? activeTime;

  ///在线时间
  String? onlineTime;

  /// ResKey.thingsEffective.tr, //"有效",时间
  String? validTime;

  ///开始回话时间时间
  String? sessionStartTime;

  ///设备类型
  int? productType;

  int? deviceId;

  ///光伏装机容量
  String? installedCapacity;

  ///设备商 1-永泰数能
  String? manufacturer;

  ///设备型号
  String? model;
  String? paramsKeyKey;

  ///1-直流桩 2-交流桩
  PileType? pileType;

  ///充电枪数量
  int? gunNumVal;

  ///充电主机数量
  int? tcuNumVal;

  ///备注 *
  String? remark;

  ///关联的站点
  String? siteCode;

  ///站点名称
  String? siteName;

  ///站点id
  int? siteId;

  ///设备编码
  String? sn;

  ///用户id
  int? uid;

  ///更新者
  String? updateBy;

  ///更新时间
  String? updateTime;

  /// 设备类型
  String? productTypeName;

  // 所属单元名称
  String? subsystemName;

  // 录入人名称
  String? createUserName;

  // 所属单元id
  int? subsystemId;

  // 告警状态
  DeviceAlarmStatus? alarmStatus;
  int? status;

  // 软件版本
  String? softVersion;

  String? factoryName;
  // 通信参数类型
  int? paramConfigType;

  // 配置参数类型
  int? productConfigType;

  // 产品id
  int? productId;

  // 设备参数配置
  DeviceConfigModel? config;
  // 主从关系
  MasterSlaveModeType? masterSlaveMode;

  // 主从系统名称
  String? masterSlaveSystemName;

  //简称
  String? forShort;

  // 站点地址
  String? address;

  double? longitude;

  double? latitude;

  int? map;

  //额定功率
  String? ratedPower;

  ProductIDType? get productIDTypeEnum => ProductIDType.values.firstWhereOrNull(
        (element) => element.value == productId,
      );

  ProductType? get productTypeEnum => ProductType.values.firstWhereOrNull(
        (element) => element.value == productId,
      );

  MapType? get mapType => MapType.values.firstWhereOrNull(
        (element) => element.value == map,
      );

  factory DeviceModel.fromJson(Map<String, dynamic> json) =>
      _$DeviceModelFromJson(json);

  Map<String, dynamic> toJson() => _$DeviceModelToJson(this);
}

///1-直流桩 2-交流桩
@JsonEnum(valueField: "value")
enum PileType {
  direct(1),
  alternating(2);

  final int value;
  const PileType(this.value);
}
